package com.jiangyg.mall.order.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.order.dto.OrderReturnApplyDTO;
import com.jiangyg.mall.order.service.OrderReturnApplyService;
import com.jiangyg.mall.order.vo.OrderReturnApplyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：订单退货申请控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:36:28
 */
@RestController
@RequestMapping("/order/orderReturnApply")
public class OrderReturnApplyController {

    /**
     * 订单退货申请接口
     */
    private final OrderReturnApplyService orderReturnApplyService;

    @Autowired
    public OrderReturnApplyController(OrderReturnApplyService orderReturnApplyService) {
        this.orderReturnApplyService = orderReturnApplyService;
    }

    /**
     * 功能描述：订单退货申请分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页订单退货申请
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<OrderReturnApplyVO>> select(HttpServletRequest request, @RequestBody Pagination<OrderReturnApplyVO> pagination) throws Exception {
        return Result.ok(orderReturnApplyService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改订单退货申请
     *
     * @param request 请求
     * @param dto     订单退货申请
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated OrderReturnApplyDTO dto) throws Exception {
        return Result.saveOrUpdate(orderReturnApplyService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取订单退货申请
     *
     * @param request 请求
     * @param orderReturnApplyId  订单退货申请ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<OrderReturnApplyVO> info(HttpServletRequest request, @RequestParam(name = "orderReturnApplyId") Long orderReturnApplyId) throws Exception {
        return Result.ok(orderReturnApplyService.selectById(orderReturnApplyId));
    }

    /**
     * 功能描述：删除订单退货申请
     *
     * @param request 请求
     * @param orderReturnApplyIds 批量删除的订单退货申请ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "orderReturnApplyIds") List<Long> orderReturnApplyIds) {
        return Result.delete(orderReturnApplyService.delete(orderReturnApplyIds));
    }

}
